/*
 *  Copyright (C) 2010 Glauco
 * 
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 * 
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 * 
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.balisunrise.swing.transaction.panel.actions;

import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.InputMap;
import javax.swing.JComboBox;
import javax.swing.JPanel;
import javax.swing.KeyStroke;
import org.balisunrise.swing.transaction.EntityActions;

/**
 *
 * @author Glauco
 */
public class EntityActionAcceleratorAction extends AbstractAction{

    EntityActions entityActions;

    @SuppressWarnings("LeakingThisInConstructor")
    public EntityActionAcceleratorAction(EntityActions entityActions) {
        this.entityActions = entityActions;
        String handler = "handlerActionPanelAcceleratorAction";
        JPanel panel = entityActions.getVisualRepresentation();
        InputMap inputMap = panel.getInputMap(JComboBox.WHEN_IN_FOCUSED_WINDOW);
        KeyStroke strokes[] = new KeyStroke[]{
                KeyStroke.getKeyStroke("control 1"),
                KeyStroke.getKeyStroke("control 2"),
                KeyStroke.getKeyStroke("control 3"),
                KeyStroke.getKeyStroke("control 4"),
                KeyStroke.getKeyStroke("control 5"),
                KeyStroke.getKeyStroke("control 6"),
                KeyStroke.getKeyStroke("control 7"),
                KeyStroke.getKeyStroke("control 8"),
                KeyStroke.getKeyStroke("control 9"),
                KeyStroke.getKeyStroke("control 0")};
        for (KeyStroke stroke : strokes) {
            inputMap.put(stroke, handler);
        }
        panel.getActionMap().put(handler, this);
    }

    public void actionPerformed(ActionEvent e) {
        System.out.println(e.toString());
    }

}
